<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$time_start = getMicro_Time();
include_once("Main_ListResult.php");
$time_end = getMicro_Time();

$fp = @file($strTemplatePath."Main_List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);

	$fp = str_replace("{Show_LottoID}", $_data["LottoID"], $fp);
	$fp = str_replace("{Show_GambleID}", $_data["GambleID"], $fp);
	$fp = str_replace("{Show_Bet_Type}", $_data["Bet_Type"], $fp);
	$fp = str_replace("{Show_PayupDate_0}", $data["PayupDate_x"][0], $fp);
	$fp = str_replace("{Show_PayupDate_1}", $data["PayupDate_x"][1], $fp);
	$fp = str_replace("{LottoContent}",  (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
	$fp = str_replace("{BetTypeContent}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_data["Bet_Type"]], $fp);
	$fp = str_replace("{Show_Types}", ((empty($_data["Types"]))?"MainAgent":$_data["Types"]), $fp);

	if(!empty($StockID)){
		$fp = preg_replace("/<!--@ ShowBar Start @\/\/-->.+<!--@ ShowBar End @\/\/-->/s", "", $fp);
	}

	while(list($k, $v) = each($_strAccount_StockMain)){
		$fp = str_replace("{".$k."}", $v, $fp);
	}

	preg_match("/<!--@ GAgentResult Start @\/\/-->(.+)<!--@ GAgentResult End @\/\/-->/s", $fp, $A);
	preg_match("/<!--@ ShareholderResult Start @\/\/-->(.+)<!--@ ShareholderResult End @\/\/-->/s", $fp, $G);
	preg_match("/<!--@ SuppleGAgentResult Start @\/\/-->(.+)<!--@ SuppleGAgentResult End @\/\/-->/s", $fp, $SA);
	preg_match("/<!--@ SuppleShareholderResult Start @\/\/-->(.+)<!--@ SuppleShareholderResult End @\/\/-->/s", $fp, $SG);
	preg_match("/<!--@ ALLResult Start @\/\/-->(.+)<!--@ ALLResult End @\/\/-->/s", $fp, $S);
	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$sumSubRateResult = 0;
	$sumMainRateResult = 0;
	$sumStockResult = 0;
	$sumStockRateResult = 0;
	$sumrealMemStake = 0;
	$sumStockComm = 0;
	$Ctotals = 0;
	$CMemStake = 0;
	$CSubIncome = 0;
	$CSubRateResult = 0;
	$CMainRateResult = 0;
	$CStockRateResult = 0;
	$CStockResult = 0;
	$CrealMemStake = 0;
	$CStockComm = 0;
	$StockID = "";
	//一般帳
	if(is_array($arrRows[0])){
		while(list($k, $Rows) = each($arrRows[0])){
			if(!empty($StockID) && $StockID != $Rows -> StockID){
				$tmpG = str_replace("{Show_Shareholder}", $arrAccount[$StockID], $G[1]);
				$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
				$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
				$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f", $sumSubIncome), $tmpG);
				$tmpG = str_replace("{Percentage}", round($sumrealMemStake / $CrealMemStake,4), $tmpG);
				$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f", $sumSubRateResult), $tmpG);
				$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f", $sumMainRateResult), $tmpG);
				$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
				$tmpG = str_replace("{sumStockComm}", sprintf("%.2f", $sumStockComm), $tmpG);
				$tmpG = str_replace("{sumStockRateWin}", sprintf("%.1f", $sumMainRateResult - $sumStockRateResult - $sumStockComm), $tmpG);
				$tmpG = str_replace("{sumStockWin}", sprintf("%.1f", $sumMainRateResult - $sumStockRateResult), $tmpG);
				$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f", $sumrealMemStake), $tmpG);
				$tmpG = str_replace("{sumStockResult}", sprintf("%.1f", $sumStockResult), $tmpG);
				$strCon .= $tmpG;
				$sumtotals = 0;
				$sumMemStake = 0;
				$sumSubIncome = 0;
				$sumSubRateResult = 0;
				$sumMainRateResult = 0;
				$sumrealMemStake = 0;
				$sumStockRateResult = 0;
				$sumStockResult = 0;
				$sumStockComm = 0;
			}
			$StockID = $Rows -> StockID;
			$realMemStake = $Rows -> realMemStake;
			$tmpA = str_replace("{Show_GAgent}", $arrAccount[$Rows -> MainID], $A[1]);
			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{Show_StockID}", $Rows -> StockID, $tmpA);
			$tmpA = str_replace("{Show_MainID}", $Rows -> MainID, $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f", $Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{SubIncome}", sprintf("%.1f", $Rows -> SubIncome), $tmpA);
			$tmpA = str_replace("{SubRateResult}", sprintf("%.1f", $Rows -> SubRateResult), $tmpA);
			$tmpA = str_replace("{MainRateResult}", sprintf("%.1f", $Rows -> MainRateResult), $tmpA);
			$tmpA = str_replace("{StockResult}", sprintf("%.1f", $Rows -> StockResult), $tmpA);
			$tmpA = str_replace("{StockMainRate}", $Rows -> MainRate - $Rows -> StockRate, $tmpA);
			$tmpA = str_replace("{StockRate}", $Rows -> StockRate, $tmpA);
			$tmpA = str_replace("{StockComm}", sprintf("%.2f", $Rows -> StockComm), $tmpA);
			$tmpA = str_replace("{StockRateWin}", sprintf("%.1f", $Rows -> MainRateResult - $Rows -> StockRateResult - $Rows -> StockComm), $tmpA);
			//$tmpA = str_replace("{StockWin}", sprintf("%.1f", ($Rows -> StockResult - $Rows -> StockRateResult)), $tmpA);
			$tmpA = str_replace("{StockWin}", sprintf("%.1f", $Rows -> MainRateResult - $Rows -> StockRateResult), $tmpA);
			$tmpA = str_replace("{StockRateResult}", sprintf("%.1f", $Rows -> StockRateResult), $tmpA);
			$tmpA = str_replace("{realMemStake}", sprintf("%.1f", $realMemStake), $tmpA);
			$strCon .= $tmpA;
			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumSubIncome += $Rows -> SubIncome;
			$sumSubRateResult += $Rows -> SubRateResult;
			$sumMainRateResult += $Rows -> MainRateResult;
			$sumrealMemStake += $realMemStake;
			$sumStockResult += $Rows -> StockResult;
			$sumStockRateResult += $Rows -> StockRateResult;
			$sumStockComm += $Rows -> StockComm;

			$Ctotals += $Rows -> totals;
			$CMemStake += $Rows -> MemStake;
			$CSubIncome += $Rows -> SubIncome;
			$CSubRateResult += $Rows -> SubRateResult;
			$CMainRateResult += $Rows -> MainRateResult;
			$CStockResult += $Rows -> StockResult;
			$CStockRateResult += $Rows -> StockRateResult;
			$CrealMemStake += $realMemStake;
			$CStockComm += $Rows -> StockComm;
		}
	}
	$tmpG = str_replace("{Show_Shareholder}",$arrAccount[$StockID], $G[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
	$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f", $sumSubIncome), $tmpG);
	$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f", $sumSubRateResult), $tmpG);
	$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f", $sumMainRateResult), $tmpG);
	$tmpG = str_replace("{sumStockComm}", sprintf("%.2f", $sumStockComm), $tmpG);
	$tmpG = str_replace("{sumStockRateWin}", sprintf("%.1f", $sumMainRateResult - $sumStockRateResult - $sumStockComm), $tmpG);
	//$tmpG = str_replace("{sumStockWin}", sprintf("%.1f", ($sumStockResult - $sumStockRateResult)), $tmpG);
	$tmpG = str_replace("{sumStockWin}", sprintf("%.1f", ($sumMainRateResult - $sumStockRateResult)), $tmpG);
	$tmpG = str_replace("{sumStockResult}", sprintf("%.1f", $sumStockResult), $tmpG);
	$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
	$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f", $sumrealMemStake), $tmpG);
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ GAgentResult Start @\/\/-->.+<!--@ ShareholderResult End @\/\/-->/s", $strCon, $fp);

	//補貨帳
	$strCon = "";
	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$sumSubRateResult = 0;
	$sumMainRateResult = 0;
	$sumrealMemStake = 0;
	$sumStockRateResult = 0;
	$sumStockResult = 0;
	$sumStockSuppleWin = 0;
	if(is_array($arrRows[1])){
		while(list($k, $Rows) = each($arrRows[1])){
			$StockID = $Rows -> StockID;
			$realMemStake = $Rows -> realMemStake;
			$tmpA = str_replace("{Show_GAgent}", $arrAccount[$Rows -> MainID], $SA[1]);
			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{Show_StockID}", $Rows -> StockID, $tmpA);
			$tmpA = str_replace("{Show_MainID}", $Rows -> MainID, $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f", $Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{SubIncome}", sprintf("%.1f", $Rows -> SubIncome), $tmpA);
			$tmpA = str_replace("{SubRateResult}", sprintf("%.1f", $Rows -> SubRateResult), $tmpA);
			$tmpA = str_replace("{MainRateResult}", sprintf("%.1f", $Rows -> MainRateResult), $tmpA);
			$tmpA = str_replace("{StockResult}", sprintf("%.1f", $Rows -> StockResult), $tmpA);
			$tmpA = str_replace("{StockMainRate}", $Rows -> MainRate - $Rows -> StockRate, $tmpA);
			$tmpA = str_replace("{StockComm}", sprintf("%.2f", $Rows -> StockComm), $tmpA);
			$tmpA = str_replace("{StockRateWin}", sprintf("%.1f", 0), $tmpA);
			$tmpA = str_replace("{StockWin}", sprintf("%.1f", -1*$Rows -> StockRateResult), $tmpA);
			$tmpA = str_replace("{StockRate}", $Rows -> StockRate, $tmpA);
			$tmpA = str_replace("{StockRateResult}", sprintf("%.1f", $Rows -> StockRateResult), $tmpA);
			$tmpA = str_replace("{realMemStake}", sprintf("%.1f", $realMemStake), $tmpA);
			$strCon .= $tmpA;
			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumSubIncome += $Rows -> SubIncome;
			$sumSubRateResult += $Rows -> SubRateResult;
			$sumMainRateResult += $Rows -> MainRateResult;
			$sumrealMemStake += $realMemStake;
			$sumStockResult += $Rows -> StockResult;
			$sumStockRateResult += $Rows -> StockRateResult;
			$sumStockSuppleWin += $Rows -> StockRateResult*-1;
			$sumStockComm += $Rows -> StockComm;

			$Ctotals += $Rows -> totals;
			$CMemStake += $Rows -> MemStake;
			$CSubIncome += $Rows -> SubIncome;
			$CSubRateResult += $Rows -> SubRateResult;
			$CMainRateResult += $Rows -> MainRateResult;
			$CStockResult += $Rows -> StockResult;
			$CStockRateResult += $Rows -> StockRateResult;
			$CrealMemStake += $realMemStake;
		}
	}
	$tmpG = str_replace("{Show_Shareholder}",$arrAccount[$StockID], $SG[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f", $sumMemStake), $tmpG);
	$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f", $sumSubIncome), $tmpG);
	$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f", $sumSubRateResult), $tmpG);
	$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f", $sumMainRateResult), $tmpG);
	$tmpG = str_replace("{sumStockComm}", sprintf("%.2f", $sumStockComm), $tmpG);
	$tmpG = str_replace("{sumStockRateWin}", sprintf("%.1f", 0), $tmpG);
	$tmpG = str_replace("{sumStockWin}", sprintf("%.1f", $sumStockSuppleWin), $tmpG);
	$tmpG = str_replace("{sumStockResult}", sprintf("%.1f", $sumStockResult), $tmpG);
	$tmpG = str_replace("{sumStockRateResult}", sprintf("%.1f", $sumStockRateResult), $tmpG);
	$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f", $sumrealMemStake), $tmpG);
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ SuppleGAgentResult Start @\/\/-->.+<!--@ SuppleShareholderResult End @\/\/-->/s", $strCon, $fp);

	$tmpS = str_replace("{Ctotals}", number_format($Ctotals), $S[1]);
	$tmpS = str_replace("{CMemStake}", sprintf("%.1f", $CMemStake), $tmpS);
	$tmpS = str_replace("{CSubIncome}", sprintf("%.1f", $CSubIncome), $tmpS);
	$tmpS = str_replace("{CSubRateResult}", sprintf("%.1f", $CSubRateResult), $tmpS);
	$tmpS = str_replace("{CMainRateResult}", sprintf("%.1f", $CMainRateResult), $tmpS);
	$tmpS = str_replace("{CStockResult}", sprintf("%.1f", $CStockResult), $tmpS);
	$tmpS = str_replace("{CStockComm}", sprintf("%.2f", $CStockComm), $tmpS);
	$tmpS = str_replace("{CStockRateWin}", sprintf("%.1f", $CMainRateResult - $CStockRateResult + $sumStockSuppleWin - $CStockComm), $tmpS);
	//$tmpS = str_replace("{CStockWin}", sprintf("%.1f", ($CStockResult - $CStockRateResult + $sumStockSuppleWin)), $tmpS);
	$tmpS = str_replace("{CStockWin}", sprintf("%.1f", $CMainRateResult - $CStockRateResult + $sumStockSuppleWin), $tmpS);
	$tmpS = str_replace("{CStockRateResult}", sprintf("%.1f", $CStockRateResult), $tmpS);
	$tmpS = str_replace("{CrealMemStake}", sprintf("%.1f", $CrealMemStake), $tmpS);
	$fp = preg_replace("/<!--@ ALLResult Start @\/\/-->.+<!--@ ALLResult End @\/\/-->/s", $tmpS, $fp);

$fp .= "\n<a style='font-size: 10px; color: #DDDDDD'>".(string)($time_end - $time_start)."</a>";
//輸出
WebOutputHTML($fp, 1);
?>